<?php
class Caso extends AppModel {
	var $name = 'Caso';
	var $validate = array(
		'hospital_ivss' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'Debe ingresar el nombre del Hospital',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'cedula_trabajador' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
			'isUnique' => array(
				'rule' => array('isUnique'),
				'message' => 'Este número de cédula ya esta registrado en el sistema.',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				'on' => 'create', // Limit validation to 'create' or 'update' operations//
			),
			'cedula' => array(
				'rule' => array('custom', '/^[VE]{1}[0-9]{7,}$/'),
				'message' => 'La cédula ingresada no cumple con el formato requerido. Ejemplo: V1234567'
			)

		),
		'fecha_apertura' => array(
			'date' => array(
				'rule' => array('date', 'dmy'),
				'message' => 'El formato de fecha es incorrecto, por favor ingrese la fecha con el calendario ó con el formato: dd/mm/yyyy',
				'allowEmpty' => true,
				'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'Medico' => array(
			'className' => 'Medico',
			'foreignKey' => 'medico_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'NivelEducativo' => array(
			'className' => 'NivelEducativo',
			'foreignKey' => 'nivel_educativo_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Trabajador' => array(
			'className' => 'Trabajador',
			'foreignKey' => 'cedula_trabajador',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	var $hasMany = array(
		'Antecedente' => array(
			'className' => 'Antecedente',
			'foreignKey' => 'caso_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Atencion' => array(
			'className' => 'Atencion',
			'foreignKey' => 'caso_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Conclusion' => array(
			'className' => 'Conclusion',
			'foreignKey' => 'caso_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Consulta' => array(
			'className' => 'Consulta',
			'foreignKey' => 'caso_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Diagnostico' => array(
			'className' => 'Diagnostico',
			'foreignKey' => 'caso_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Examen' => array(
			'className' => 'Examen',
			'foreignKey' => 'caso_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Manifestacion' => array(
			'className' => 'Manifestacion',
			'foreignKey' => 'caso_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);
	
	function getTrayecto($caso_id){
		$recursive = $this->recursive;
		$this->recursive = 0;
		$caso = $this->read('trayecto', $caso_id);
		$this->recursive = $recursive;
		//pr($trayecto);
		return $caso['Caso']['trayecto'];
	}
	
	function setTrayecto($caso_id, $value){
		$this->id = $caso_id;
		$this->saveField('trayecto', $value);
	}
	
	function getCreador($caso_id){
		$recursive = $this->recursive;
		$this->recursive = 0;
		$usuario_id = $this->read('usuario_id', $caso_id);
		$this->recursive = $recursive;
		return $usuario_id['Caso']['usuario_id'];
	}

}
?>